package com.lxy.code.api;

import com.lxy.code.service.LagouAuthCodeService;
import com.lxy.common.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 123
 * @date 2020/6/22 18:14
 * @description
 */
@RestController
@RequestMapping("code")
public class LagouCodeApi {

    @Autowired
    private LagouAuthCodeService lagouAuthCodeService;

    @PostMapping("create/{email}")
    public JsonResult sendCode(@PathVariable String email){
        Boolean send=lagouAuthCodeService.sendCode(email);
        if(send){
           return JsonResult.ok("发送成功");
        }else {
            return JsonResult.error("发送失败");
        }
    }

    @PostMapping("validate/{email}/{code}")
    public JsonResult authCode(@PathVariable String email, @PathVariable String code){
        return lagouAuthCodeService.validateCode(email,code);
    }

}
